import 'package:flutter/material.dart';

class HouseItem extends StatefulWidget {
  HouseItem({super.key, required this.data});
  Map data;

  @override
  State<HouseItem> createState() => _HouseItemState();
}

class _HouseItemState extends State<HouseItem> {
  Map _data = {};
  @override
  void initState() {
    super.initState();
    // print(widget.data);
    setState(() {
      _data = widget.data;
    });
  }

  // 基于 房屋状态 设置一个映射关系，根据 status 返回对应的结构
  _statusToItem(int status) {
    List tagList = [
      {},
      {
        'title': '正在审核',
        'bgcolor': const Color.fromARGB(50, 0, 0, 255),
        'color': const Color.fromARGB(255, 0, 0, 255)
      },
      {
        'title': '审核通过',
        'bgcolor': const Color.fromARGB(50, 0, 255, 0),
        'color': const Color.fromARGB(255, 0, 255, 0)
      },
      {
        'title': '审核失败',
        'bgcolor': const Color.fromARGB(50, 255, 0, 0),
        'color': const Color.fromARGB(255, 255, 0, 0)
      },
    ];

    return Container(
        padding: const EdgeInsets.only(left: 5, right: 5, top: 2, bottom: 2),
        decoration: BoxDecoration(
            color: tagList[status]['bgcolor'],
            borderRadius: BorderRadius.circular(5)),
        child: Text(tagList[status]['title'],
            style: TextStyle(color: tagList[status]['color'])));
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.pushNamed(context, '/house_detail',
            arguments: {'id': _data['id']});
      },
      child: Container(
          padding: const EdgeInsets.all(10),
          decoration: const BoxDecoration(
            color: Colors.white,
          ),
          child: Column(
            children: [
              Row(
                children: [
                  Expanded(child: Text(_data['point'])),
                  const Spacer(),
                  //   Container(
                  //       padding: const EdgeInsets.only(
                  //           left: 5, right: 5, top: 2, bottom: 2),
                  //       decoration: BoxDecoration(
                  //           color: const Color.fromARGB(50, 91, 177, 227),
                  //           borderRadius: BorderRadius.circular(5)),
                  //       child: const Text('已绑定',
                  //           style: TextStyle(
                  //               color: Color.fromARGB(255, 85, 145, 175))))
                  _statusToItem(_data['status']),
                ],
              ),
              const SizedBox(height: 15),
              Row(
                children: [
                  const Text(
                    '房间号',
                    style: TextStyle(color: Colors.grey),
                  ),
                  const Spacer(),
                  Expanded(
                      child: Text(
                    _data['room'],
                    textAlign: TextAlign.right,
                  )),
                ],
              ),
              const SizedBox(height: 15),
              Row(
                children: [
                  const Text(
                    '业主',
                    style: TextStyle(color: Colors.grey),
                  ),
                  const Spacer(),
                  Expanded(
                      child: Text(
                    _data['name'],
                    textAlign: TextAlign.right,
                  )),
                ],
              ),
            ],
          )),
    );
  }
}
